package com.woniuxy.auth.controller;

import com.woniuxy.auth.service.ManagerService;
import com.woniuxy.auth.service.MenuService;
import com.woniuxy.commons.entity.auth.vo.RbacManagerVo;
import com.woniuxy.commons.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO:
 * <P> Date: 2022/4/28:8:14
 * <P> Description:
 */
@RestController
@RequestMapping("/auth/user")
@Api(tags = "用户认证/鉴权控制器")
public class AuthController {


    @Resource
    private ManagerService managerService;


    @Resource
    private MenuService menuService;


    @PostMapping("/login")
    @ApiOperation(value = "认证方法")
    public Result login(@RequestBody RbacManagerVo rbacManagerVo,
                                HttpServletResponse response) {
        //通过账号作为查询条件去查询数据库信息 判断账号密码

        return managerService.verity(rbacManagerVo,response);

    }


    /**
     * <P>Author ideaAdmin
     * <P>TODO: 鉴权方法 通过账号和 权限 来认证
     * <P>Date 15:48 2022/3/30
     * <P>* @param uname
     * <P>@param perms
     * <P>* @return com.woniuxy.commons.bean.ResponseResult<java.lang.Object>
     **/
    @ApiOperation(value = "鉴权方法 通过refreshToken 查询redis 和 权限 来认证")
    @GetMapping("/hasPerms/{refreshToken}/{perms}")
    public Result hasPerms(@PathVariable("refreshToken") String refreshToken,
                                   @PathVariable("perms") String perms) {

        return menuService.hasPerms(refreshToken,perms);


    }
}
